<?PHP
 session_start();
 include("admin/include/db.php");
 include("includes/session.php");
 
 $userId = $_SESSION['user_id'];
 
 
 if(isset($_REQUEST) && $_REQUEST['submit'] != ''){
 	
	$oldPassword 		= mysql_real_escape_string($_REQUEST['old_password']); 
	$newPassword		= mysql_real_escape_string($_REQUEST['new_password']);
	
	$sqlPassword 		= mysql_query("SELECT * FROM software_user WHERE password  = '".$oldPassword."' AND Id = '$userId'");
	$resPassword 		= mysql_fetch_array($sqlPassword);
	if($resPassword["Id"] > 0){
		$updatePassword  = "UPDATE software_user SET password  = '".$newPassword."' WHERE  Id = '$userId'";	
		if(mysql_query($updatePassword))
			header("location:change_password.php?msg=1");
		else
			header("location:change_password.php?msg=2");
	}else{
		header("location:change_password.php?msg=2");
	}

	exit();		
 }

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=TITLE_WEBSITE?></title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<script>
function validation(){
	
	var message = '';
	
	
	if(document.getElementById("old_password").value == ""){
		message += 'Please enter your old password\n';
	}
	if(document.getElementById("new_password").value == ""){
		message += 'Please enter your new password\n';
	}
	if(document.getElementById("confirm_password").value == ""){
		message += 'Please enter your confirm password\n';
	}
	if(document.getElementById("confirm_password").value != document.getElementById("new_password").value ){
		message += 'Please enter same password in both confirm and new password options';
	}
	
	if(message != ""){
		alert(message);
		return false;
	}
	
	
}
</script>
<body>
<center>
<div style="background:#179cc1; height:3px">&nbsp;</div>
<div style="width:990px;" align="center">
		<div id="header">
		<?php
    		include("includes/header.php");
   		?>
        </div>
    <div style="margin-top:20px;">
    	 <div style=" width:25%; float:left" >
             <?php 
			    if($_SESSION['user_type'] == 'Student')
				{
			 		include("includes/studentLeftMenu.php");
				}elseif($_SESSION['user_type'] == 'Trainer'){
					include("includes/trainerLeftMenu.php");
				}
				?>
        </div>
        <div style="width:75%;float:left">
        	<div style="margin-top:20px;">
    	<form id="form_login" name="form_login" method="post" onsubmit="return login_validation()" >
    	<?php
		$msg = $_REQUEST['msg'];
        if($msg != "")
		{
			if($msg == 1){
				$showMessage = 'Your password has been changed successfully';
				$clsMessage = 'clsSuccess';	
			}else if($msg == 2){
				$showMessage = 'Sorry,your password does not changed';
				$clsMessage = 'clsError';
			}
		?>
        <div align="left" class="<?=$clsMessage?>" style="margin-bottom:10px" >
           &nbsp; 	 <?=$showMessage?>
        </div>
        <?php
		}
		?>
        
        </form>
        <form id="form_register" name="form_register" method="post" onsubmit="return validation()" >
        <div style="width:85%; margin-left:40px" >
        	<div align="left" >
            	<span class="headingOrange" ><strong>Change your password</strong></span>
            </div>
            <div class="text1"  align="left" style=" padding-top:18px;">
         		 <div  >	
                    <div style="float:left; width:30%" class="text" >Old Password:</div>
                    <div style="float:left; width:70%" ><input type="password" id="old_password" class="textBox" name="old_password" value="<?=$_REQUEST['old_password']?>" maxlength="30" /> </div>
                    <div style=" clear:both" ></div>
                </div>
                
                <div style="margin-top:10px"  >	
                    <div style="float:left; width:30%" class="text" >New Password:</div>
                    <div style="float:left; width:70%" ><input type="password" id="new_password" class="textBox" name="new_password" value="<?=$_REQUEST['new_password']?>"  maxlength="30" /> </div>
                    <div style=" clear:both" ></div>
                </div>
                <div  style="margin-top:10px" >	
                    <div style="float:left; width:30%" class="text" >Confirm Password:</div>
                    <div style="float:left; width:70%" ><input type="password" id="confirm_password" class="textBox" name="confirm_password" value="<?=$_REQUEST['confirm_password']?>" maxlength="30"  /> </div>
                    <div style=" clear:both" ></div>
                </div>
                
                 <div style="margin-top:10px;" align="center">	
                 	<input type="hidden" id="action" name="action" value="change_password"  />
                   	<input type="submit" class="button" name="submit" id="submit" value="Change Password"  />
                </div>
                 
            </div>
        </div>
        </form>
      <div style="clear:both"></div>
    </div>
        	
        </div>
        <div style="clear:both"></div>
    </div>
    
    <div style="margin-top:23px; margin-bottom:21px" align="center" >
    	<?php
									$sqlAdvertise = mysql_query("SELECT * FROM software_advertise 
																	WHERE 
																		banner_status = 'Y' AND banner = 2
																		ORDER BY RAND()
																		");
									$resAdvertise = mysql_fetch_array($sqlAdvertise);
							
									$imgPath  = 'admin/upload_images/'.$resAdvertise["banner_image"];
									
								?>
								
    </div>
   </div>
   <div id="footer">
  		<?php include("includes/footer.php")?>
   </div>
</div>
	</div>
</center>
</body>
</html>
